package com.lovo.view;

import com.lovo.javafxComponent.LovoAccordion;
import com.lovo.javafxComponent.LovoImage;
import com.lovo.view.dept.DeptPane;
import com.lovo.view.emp.EmpPane;
import com.lovo.view.info.UpdatePwdPane;
import com.lovo.view.school.SchoolPane;
import com.lovo.view.total.TotalPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;

import java.util.ArrayList;
import java.util.List;

/**
 * 主界面
 * 
 * @author lenovo
 *
 */
public class MainView extends BorderPane {
	/** 内容容器 */
	private Pane mainPane = new Pane();
	/**根容器*/
	private BorderPane root;

	public MainView(BorderPane root) {

		this.root = root;
		this.setCenter(mainPane);
		new LovoImage("image/main.jpg", 0, 0, 800, 700, mainPane);

		this.initAccordion();
		
		root.setCenter(this);
	}
	/**
	 * 根据选项切换界面
	 * @param itemName 选项
	 */
	private void changePane(String itemName) {
		mainPane.getChildren().clear();
		if("员工管理".equals(itemName)) {
			mainPane.getChildren().add(new EmpPane());
		}
		else if("部门管理".equals(itemName)) {
			mainPane.getChildren().add(new DeptPane());
		}
		else if("学校管理".equals(itemName)) {
			mainPane.getChildren().add(new SchoolPane());
		}
		else if("地区统计".equals(itemName)) {
			mainPane.getChildren().add(new TotalPane());
		}
		else if("修改密码".equals(itemName)) {
			mainPane.getChildren().add(new UpdatePwdPane(root));
		}
	}

	//------------------------------------------
	/**
	 * 初始化手风琴组件
	 */
	private void initAccordion() {
		List<String> itemList = new ArrayList<>();
		itemList.add("四川网脉CRM系统:员工管理,部门管理,学校管理,地区统计,修改密码");

		LovoAccordion accordion = new LovoAccordion(
				itemList.toArray(new String[]{}), 200, 400) {

			@Override
			public void listSelectEvent(String itemName) {
				changePane(itemName);
			}
		};
		this.setLeft(accordion);
	}
	
	
}
